"""
交易 - 退款通知相关模型
"""

from typing import Dict, Any, Optional


class RefundsNotifyMessage:
    """退款结果回调通知"""
    
    def __init__(self, data_dict=None):
        """
        初始化退款结果回调通知
        
        Args:
            data_dict: 数据字典
        """
        self.status = None  # 状态 1：待确认 2：成功 3：失败
        self.summary = None  # 回调描述
        self.mch_id = None  # 商户号
        self.transaction_id = None  # 平台订单号
        self.out_trade_no = None  # 外部订单号
        self.chn_transaction_id = None  # 渠道订单号
        self.ori_out_trade_no = None  # 原外部订单号
        self.ori_transaction_id = None  # 原平台订单号
        self.total_fee = None  # 交易金额
        self.trans_time = None  # 交易时间
        self.success_time = None  # 退款完成时间
        
        if data_dict:
            self.status = data_dict.get('status')
            self.summary = data_dict.get('summary')
            self.mch_id = data_dict.get('mch_id')
            self.transaction_id = data_dict.get('transaction_id')
            self.out_trade_no = data_dict.get('out_trade_no')
            self.chn_transaction_id = data_dict.get('chn_transaction_id')
            self.ori_out_trade_no = data_dict.get('ori_out_trade_no')
            self.ori_transaction_id = data_dict.get('ori_transaction_id')
            self.total_fee = data_dict.get('total_fee')
            self.trans_time = data_dict.get('trans_time')
            self.success_time = data_dict.get('success_time')
    
    def to_dict(self) -> Dict[str, Any]:
        """转换为字典格式"""
        return {
            'status': self.status,
            'summary': self.summary,
            'mch_id': self.mch_id,
            'transaction_id': self.transaction_id,
            'out_trade_no': self.out_trade_no,
            'chn_transaction_id': self.chn_transaction_id,
            'ori_out_trade_no': self.ori_out_trade_no,
            'ori_transaction_id': self.ori_transaction_id,
            'total_fee': self.total_fee,
            'trans_time': self.trans_time,
            'success_time': self.success_time
        } 